package codetop.kuaishou.T150;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @Author: 18362
 * @Create: 2022-09-16 2:05:23 星期五
 */
class Solution {
    public int evalRPN(String[] tokens) {
        Deque<Integer> stack = new LinkedList<>();
        for (String token : tokens) {
            if (token.equals("+") || token.equals("-") || token.equals("*") || token.equals("/")) {
                Integer a = stack.pop();
                Integer b = stack.pop();
                if (token.equals("+"))
                    stack.push(a + b);
                else if (token.equals("-"))
                    stack.push(b - a);
                else if (token.equals("*"))
                    stack.push(a * b);
                else
                    stack.push(b / a);
            } else
                stack.push(Integer.parseInt(token));
        }
        return stack.peek();
    }
}